
#ifndef _DEBUG_H_
#define _DEBUG_H_

#include <stdarg.h>
#include <stdio.h>


#ifndef NDEBUG
    #if defined(ENABLE_SEMIHOST)
    #define DBG_CH_WRITE(ch, str)        printf("%s", str)
    #define DBG_CH_PRINT(ch, ...)       printf(fmt, __VA_ARGS__)
    #else
    #include "SEGGER_RTT.h"
	#define DBG_CH_PRINT(ch, ...)	SEGGER_RTT_printf(ch, __VA_ARGS__)	
	#define DBG_CH_WRITE(ch, str)	SEGGER_RTT_WriteString(ch, str)
    #endif
	
	#define DBG_CH_PRINT_BUF(ch, buf, len)	\
		do{ unsigned int i; 	\
			unsigned char *_buf = buf; unsigned int _len = (len);	\
			for(i = 0; i < _len; ++i)	DBG_CH_PRINT(ch, "%02X ", _buf[i]); \
		}while(0)
#else
#define DBG_CH_WRITE(ch, str)
#define DBG_CH_PRINT(ch, ...)
#define DBG_CH_PRINT_BUF(ch, buf, len)
#endif


#define DBG_PRINT(...)		DBG_CH_PRINT(0,  __VA_ARGS__)
#define DBG_WRITE(str)		DBG_CH_WRITE(0, str)
#define DBG_PRINT_BUF(buf, len)	DBG_CH_PRINT_BUF(0, buf, len)

#define MDBG_PRINT(m, ...)			if(m) DBG_PRINT( __VA_ARGS__)
#define MDBG_PRINT_BUF(m, buf, len)		if(m) DBG_PRINT_BUF(buf, len)
#define MDBG_WRITE(m, str)			if(m) DBG_WRITE(str)

#define MDBG_CH_PRINT(m, ch, ...)	if(m) DBG_CH_PRINT(ch, __VA_ARGS__)
#define MDBG_CH_PRINT_BUF(m, ch, buf, len)	if(m) DBG_CH_PRINT_BUF(ch, buf, len)
#define MDBG_CH_WRITE(m, ch, str)		if(m) DBG_CH_WRITE(ch, str)

#endif




